package lxt.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;
import lxt.dao.ChargeRecordDao;
import lxt.entity.ChargeRecord;
import lxt.service.ChargeRecordService;

public class ChargeRecordServiceImpl implements ChargeRecordService {
	private ChargeRecordDao chargeRecordDao;
	
	public boolean addCharge(ChargeRecord charge) throws Exception {
		this.chargeRecordDao.save(charge);
		return true;
	}

	public boolean deleteCharge(String chargeId) throws Exception {
		String[] delId = chargeId.split(",");
		for(int i=0;i<delId.length;i++){
			String idstr = delId[i];
			this.chargeRecordDao.delete(ChargeRecord.class, idstr);
		}
		return true;
	}

	public List<Map<String, Object>> loadCharge(String orderId, String clientName, String startDate,
			String endDate, Integer offset, Integer length) throws Exception {
		return this.chargeRecordDao.loadAllCharge(orderId, clientName, startDate, endDate, offset, length);
	}

	public ChargeRecord loadChargeById(String chargeId) throws Exception {
		return (ChargeRecord) this.chargeRecordDao.get(ChargeRecord.class, chargeId);
	}

	public boolean updateCharge(ChargeRecord charge) throws Exception {
		this.chargeRecordDao.update(charge);
		System.out.println("\n\n\n");
		return true;
	}
	/**
	 * 根据订单id和客户id查询nextChargeDate
	 * @param orderId
	 * @param clientId
	 * @return
	 */
	public ChargeRecord queryByNextChargeDate(String orderId,String clientId)throws Exception{
		return this.chargeRecordDao.queryByNextChargeDate(orderId, clientId);
	}
	/**
	 * get set
	 * @return
	 */
	public ChargeRecordDao getChargeRecordDao() {
		return chargeRecordDao;
	}

	public void setChargeRecordDao(ChargeRecordDao chargeRecordDao) {
		this.chargeRecordDao = chargeRecordDao;
	}

	@SuppressWarnings("unchecked")
	public List<?> loadByPageWithClient(String clientId, Date startDate, Date endDate,Integer offset,
			Integer pageSize) throws Exception {
		return this.chargeRecordDao.loadByPageWithClient(clientId, startDate, endDate, offset, pageSize);
	}

	public int countLast(ChargeRecord chargeRecord) throws Exception {
		return chargeRecordDao.countLast(chargeRecord);
	}

	public List<?> queryResumeForUpdatePre(ChargeRecord chargeRecord)
			throws Exception {
		return chargeRecordDao.queryResumeForUpdatePre(chargeRecord);
	}

}
